from django.db import models

# Create your models here.
#权限子表
class Metalist(models.Model):
    id=models.IntegerField(primary_key=True)
    icon=models.CharField(max_length=32,verbose_name='图标')
    title=models.CharField(verbose_name='权限名称',max_length=32)
    type=models.CharField(default='menu',max_length=32)

#权限表
class Menu(models.Model):
    name=models.CharField(verbose_name='路径名称',max_length=32,default='')
    path=models.CharField(verbose_name='权限路径',max_length=32)
    component=models.CharField(verbose_name='组件名称',max_length=32,null=True)
    mid=models.ForeignKey(to='self',on_delete=models.CASCADE,default=None,null=True,related_name='children')
    metalist=models.ForeignKey(Metalist,on_delete=models.CASCADE,default=None)

    

#角色表
class Role(models.Model):
    Gender_choices=(
        (0,'正常'),
        (1,'锁定')
    )
    role=models.CharField(verbose_name='角色名称',max_length=32)
    status=models.IntegerField(choices=Gender_choices,default=0,verbose_name='角色状态')
    menus=models.ManyToManyField(to=Menu)
    def __str__(self):
        return self.role
    class Meta:
        db_table='scuiadminrole'

#用户表
class User(models.Model):
    user=models.CharField(verbose_name='用户名',max_length=32)
    password=models.CharField(verbose_name='密码',max_length=32)
    phone=models.CharField(verbose_name='手机号',max_length=11)
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    role=models.ManyToManyField(Role)
    headPicture=models.URLField(verbose_name='头像',blank=True)
    def __str__(self):
        return self.user
    class Meta:
        db_table='scuiadminuser'
